//
// Created by dddgzc on 2025/2/1.
//

#include "../include/Bullet.h"

#include "Content.h"

void Bullet::setDamage(int damage) {
    this->damage = damage;
}

int Bullet::getDamage() const {
    return damage;
}

void Bullet::setPosition(float x, float y) {
    position.x = x;
    position.y = y;
}

Vector2 & Bullet::getPosition() {
    return position;
}

Vector2 & Bullet::getSize() {
    return this->size;
}

void Bullet::setVelocity(float x, float y) {
    velocity.x = x;
    velocity.y = y;
}

void Bullet::setCollideTarget(PlayerID id) {
    targetPlayerID = id;
}

PlayerID Bullet::getCollideTarget() const {
    return targetPlayerID;
}

void Bullet::setCallback(std::function<void()> callback) {
    this->callback = callback;
}

void Bullet::setValid(bool flag) {
    this->valid = flag;
}

bool Bullet::getValid() const {
    return valid;
}

bool Bullet::checkCanRemove() const {
    return canRemove;
}

void Bullet::onCollide() {
    if (callback != nullptr) {
        callback();
    }
}

bool Bullet::checkCollision(const Vector2 &position, const Vector2 &size) {
    return this->position.x + this->size.x / 2 >= position.x
        && this->position.x + this->size.x / 2 <= position.x + size.x
        && this->position.y + this->size.y / 2 >= position.y
        && this->position.y + this->size.y / 2 <= position.y + size.y;
}

void Bullet::onUpdate(int delta) {
}

void Bullet::onDraw(const Camera &camera) {
}

bool Bullet::checkIfExceedsScreen() const {
    return (position.x + size.x <= 0 || position.x + size.x >= Content::WINDOW_WIDTH
        || position.y + size.y <= 0 || position.y >= Content::WINDOW_HEIGHT);
}


